package com.common.manager;

import org.springframework.stereotype.Component;

import com.common.model.StaffInfoModel;
import com.common.utils.ASObjectConvert;
import com.common.utils.MD5Crypt;
import com.framework.model.IData;
import com.framework.model.impl.DataMap;

import flex.messaging.io.amf.ASObject;


@Component
public class UserInfoManager  extends BaseManager{
	
	@Override
	public void setSqlMapNameSpace() {
		this.sqlMapNameSpace = "com.common.security.model.userInfo";
	}
	

	/**
	 * 功能：更新操作
	 * @param object
	 * @return
	 */
	public IData updatePwd(ASObject object) {
		log.debug("update...."+object.toString());
		IData data =  ASObjectConvert.convertASObject2JavaObject(object,DataMap.class);
		try {
			if(object!=null){
				String password= String.valueOf(data.get("password"));
				String password1=password;
				if(password!=null && !"".equals(password)){
					password1 = MD5Crypt.encrypt(password);
				}
				data.put("password", password1);
			    super.updateObject(data);
			    data.put("password", password);
			    data.put("success", "OK");
			}
		} catch (Exception e) {
			e.printStackTrace();
			 data.put("error", "failser");
			log.error("Exception===="+e.getMessage());
		}
		return data;
	}

	/**
	 * 功能：执行登录校验
	 * @param userInfo
	 * @return
	 */
	public StaffInfoModel checkUser(ASObject object) {
		IData data =  ASObjectConvert.convertASObject2JavaObject(object,DataMap.class);
		// TODO Auto-generated method stub
		System.out.println("..............checkUser...");
		String password = String.valueOf(data.get("loginPwd"));
		if(password!=null && !"".equals(password)){
			password = MD5Crypt.encrypt(password);
		}
		data.put("loginPwd", password);		StaffInfoModel dataMap = (StaffInfoModel)super.getObjectInfo("checkLoginUser",data);
		if(dataMap!=null){
			return dataMap;
		}
		return null;
	}

	 
}
